-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
protocols/relay/src/v2: Refactor error handling #7
Conversation
First of all: I don't feel strongly the whole That being said, for the sake of the discussion I will still write down my thoughts; I think error handling in rust in general is an interesting topic with lots of different opinions. So continuing on libp2p#2059 (comment):
Because imho said details are much more confusing than helpful. Ideally, when integrating a library, the user should look for each operation at the possible errors, differentiate between the different variants, and handle the errors accordingly. Some errors may be fatal, whereas in other cases, e.g. a timeout, the user would want to retry the operation.
So the user would be confronted with 12 variants where it's
On the contrary; it will much more likely cause them to just treat no variant separately at all, and either just wrap them if they are themselves a library (resulting in the kitchen-sink anti-pattern), or treat all variants the same, e.g. abort/ shutdown. From my perspective, the only situation where a user needs the detailed information that Now I know the latter is so far not really common in rust-libp2p. On the other hand, having a separate error variant for each step in the decoding process is not common in other rust-libp2p protocols either. Looking at fn parse_proto_msg(msg: impl AsRef<[u8]>) -> Result<IdentifyInfo, io::Error>; where And especially for the case of decoding a protobuf: Does it really make a difference if decoding the received bytes to the protobuf message failed, or if that protobuf message then contains fields that are not what we expected? Both cases are protocol violations. |
Thank you @elenaf9 for the review and the detailed suggestion. I still need to give the above more thoughts. I agree that "Just throwing all available information at the user is not always the best decision". As you pointed out above, next to using the returned error as a simple signal that the operation failed, I am also (mis-) using it as a debugging instrument, containing all relevant information.
True. I am not yet sure how to combine the simple abstraction with good debuggability.
Logging the detailed error and returning the abstracted error seems simple code-wise, but in my eyes hard to debug. E.g. you loose the coupling between log lines.
Including the detailed error in the abstracted error as a If I am not mistaken we agree that this pull request represents a step forward. Thus I am merging it. I agree that we should give error handling more thoughts in rust-libp2p, ideally coming up with consistent patterns across protocol implementations. |
See #7 for similar change in libp2p-relay.
Does the following changes:
v2/protocol/*
.ProtocolsHandlerEvent::Close
not attempting to emit events to theNetworkBehaviour
orTransport
before closingProtocolsHandler::OutEvent
and consecutively viaNetworkBehaviour::OutEvent
.